<template>
  <div>
    <TableShell :sheetParams="sheetParams" ref="tableShellRef" />
    <el-button type="primary" @click="getData">按钮</el-button>
  </div>
</template>
<script>
import TableShell from './TableShell';
import * as XLSX from 'xlsx';
export default {
  data() {
    return {
      sheetParams: {
        excelHeader: ['姓名', '年龄', '性别', '大学'],
        excelData: {
          姓名: ['张三', '赵兰', '李四'],
          年龄: ['18', '17', '20'],
          性别: ['男', '女', '男'],
          大学: ['广州大学', '深圳大学', '湖南大学'],
        },
      },
    };
  },
  methods: {
    getData() {
      const dataList = this.$refs.tableShellRef.getSheetData();
      console.log(dataList, '数据');
      let count = 1;
      const list = [];
      const celldata = dataList[0].celldata;
      const titleList = celldata.filter((x) => x.r === 0);
      const titleListKey = titleList.map((item) => item.v.v);
      console.log(titleListKey, '头部');
      while (count <= celldata[celldata.length - 1].r) {
        const data = {};
        const res = celldata.filter((x) => x.r === count);
        if (res) {
          res.forEach((x) => {
            data[titleListKey[x.c]] = x.v.v;
          });
          list.push(data);
        } else {
          continue;
        }
        count++;
      }
      console.log(list, '---->>>>');
    },
  },
  components: {
    TableShell,
  },
};
</script>
